<?php
require_once('lib/dbclass.php');
$db = new MySQL();

	


// insert ke Database tabel berita
if(isset($_POST['tambah'])){
	//upload file
	$location_file = $_FILES['gambar']['tmp_name'];
	$name_file = $_FILES['gambar']['name'];

	move_uploaded_file($location_file,"images/berita/$name_file");
	//end upload
	
	$pengirim = $_POST['pengirim'];
	$jdl = $_POST['jdl'];
	$kat = $_POST['kat'];
	$isi = $_POST['isi'];
	$tipe = $_POST['tipe'];
	
	
if($pengirim=='' OR $jdl=='' OR $kat=='' OR $isi=='' OR $name_file=='' OR $tipe==''){
	echo '<script>';
	echo "alert('Error: data yang diisikan tidak boleh kosong');";
	echo "window.location='index.php?q=15'";
	echo '</script>';
}else{
	
	if (! $db->Query("insert into berita(id_kategori,pengirim,judul,isi_berita,tanggal,gambar,jenis) 
		values('$kat','$pengirim','$jdl','$isi',now(),'$name_file','$tipe')")) $db->Kill(); 
		
	echo '<script>';
	echo "alert('Success: Anda berhasil menambah berita baru');";
	echo "window.location='index.php?q=3'";
	echo '</script>';
}
}
?>



<form class="form-horizontal" role="form" action="" method='post' enctype="multipart/form-data">
			
			<div class="form-group">
				
				<label for="pengirim" class="col-sm-2 control-label"> Pengirim   : </label>
				<div class="col-sm-10">
				<input class="form-control" type="text" name="pengirim" id="pengirim" value="<?php echo $_SESSION['session_usr'];?>" placeholder="Pengirim">
				
			</div>
			</div>

			<div class="form-group">
				
				<label for="judul" class="col-sm-2 control-label">Judul      :</label>
				<div class="col-sm-10">
				<input class="form-control" type="text" name="jdl" placeholder="Judul">
				
			</div>
			</div>
			
			<div class="form-group">
				
				<label for="kat" class="col-sm-2 control-label">Kategori   :</label>
				<div class="col-sm-10">
				<?php
						if (! $db->Query("select * from kategori where jenis ='berita'")) $db->Kill(); 
					?>
				        <br />
				    <select class="form-control" name='kat'>
				      <?php while($rs = $db->RowArray()):?>
				      <option value='<?php echo $rs[0]?>'><?php echo $rs[1]?>
				        </value>
				        <?php endwhile;?>
				    </select></td>
				</div>
	
			</div>
				<div class="form-group">
					
				<label for="body" class="col-sm-2 control-label">Isi Berita :</label>
				<div class="col-sm-10">
				<textarea class="form-control editor" name="isi" rows="12" placeholder="Page Body"></textarea>
				</div>
			</div>
			
			<div class="form-group">
				 <div class="col-sm-offset-2 col-sm-10">
			    <label for="gambar">File Gambar</label>
			    <input type="file" name="gambar">
			    <p class="help-block">Input gambar disini.</p>
			</div>
			</div>
			
			<div class="form-group">
		    <div class="col-sm-offset-2 col-sm-10">
		      <div class="checkbox">
		        <label>
		        	<input type='radio' value='Publik' name='tipe' />
					Publik
					  <input type='radio' value='Privat' name='tipe' />
					Privat </td>
		        </label>
		    </div>
		    </div>
		   	</div>
			
			
			<div class="form-group">
					
				<label for="body" class="col-sm-2 control-label"></label>
				<div class="col-sm-10">
					&nbsp;
				</div>
			</div>
			
			<div class="form-group">
   			<div class="col-sm-offset-2 col-sm-10">
			<button type="submit" class="btn btn-success">Save</button>
			<input type="hidden" name="tambah" value="Simpan">
			</div>
			</div>
			
		</form>
	
